//
//  TypeView.m
//  QuickCure
//
//  Created by 王震 on 16/9/12.
//  Copyright © 2016年 haoge. All rights reserved.
//

#import "TypeView.h"
#import "OneTypeView.h"

@implementation TypeView

-(instancetype)init{
    if (self = [super init]) {
        [self creatSubViews];
    }
    return self;
}

#define kMargin 1
#define kCount 3

-(void)creatSubViews{
    
    NSArray *titleArr = @[@"肿瘤",@"血液科",@"心血管",@"神经病",@"骨科",@"公益"];
    NSArray *titleImageArr = @[@"zl",@"xy",@"xyg",@"sj",@"gt",@"gy"];
    for (int i = 0; i < titleArr.count; i++) {
        NSString *titleStr = titleArr[i];
        UIImage *titleImage = [UIImage imageNamed:titleImageArr[i]];
        OneTypeView *typeView = [OneTypeView oneTypeViewWithTitle:titleStr image:titleImage];
        typeView.tag = i;
        [self addSubview:typeView];
    }
}

-(void)layoutSubviews{
    
    self.backgroundColor = [UIColor grayColor];
    
    CGFloat kWidth = ([UIScreen mainScreen].bounds.size.width - (kCount - 1) * kMargin) / kCount;
    CGFloat kHeight = self.bounds.size.height * 0.5;
    
    [self.subviews enumerateObjectsUsingBlock:^(__kindof OneTypeView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        NSInteger row = idx % kCount;
        NSInteger col = idx / kCount;
        
        CGFloat X = (kWidth + kMargin) * row;
        CGFloat Y = kMargin + (kHeight + kMargin) * col;
        
        obj.frame = CGRectMake(X, Y, kWidth, kHeight);
    }];
}

@end
